package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.BizTransferRecords;
import com.cykj.pos.service.IBizTransferRecordsService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 划拨记录Controller
 *
 * @author Zephyr
 * @date 2025-05-29
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/transRecords" )
public class BizTransferRecordsController extends BaseController {

    private final IBizTransferRecordsService iBizTransferRecordsService;

    /**
     * 查询划拨记录列表
     */
    @PreAuthorize("@ss.hasPermi('pos:transRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizTransferRecords bizTransferRecords) {
        startPage();
        List<BizTransferRecords> list = iBizTransferRecordsService.queryList(bizTransferRecords);
        return getDataTable(list);
    }

    /**
     * 导出划拨记录列表
     */
    @PreAuthorize("@ss.hasPermi('pos:transRecords:export')" )
    @Log(title = "划拨记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BizTransferRecords bizTransferRecords) {
        List<BizTransferRecords> list = iBizTransferRecordsService.queryList(bizTransferRecords);
        ExcelUtil<BizTransferRecords> util = new ExcelUtil<BizTransferRecords>(BizTransferRecords.class);
        return util.exportExcel(list, "transRecords" );
    }

    /**
     * 获取划拨记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:transRecords:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iBizTransferRecordsService.getById(id));
    }

    /**
     * 新增划拨记录
     */
    @PreAuthorize("@ss.hasPermi('pos:transRecords:add')" )
    @Log(title = "划拨记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizTransferRecords bizTransferRecords) {
        return toAjax(iBizTransferRecordsService.save(bizTransferRecords) ? 1 : 0);
    }

    /**
     * 修改划拨记录
     */
    @PreAuthorize("@ss.hasPermi('pos:transRecords:edit')" )
    @Log(title = "划拨记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizTransferRecords bizTransferRecords) {
        return toAjax(iBizTransferRecordsService.updateById(bizTransferRecords) ? 1 : 0);
    }

    /**
     * 删除划拨记录
     */
    @PreAuthorize("@ss.hasPermi('pos:transRecords:remove')" )
    @Log(title = "划拨记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iBizTransferRecordsService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


    @ApiOperation("查询明细")
    @PostMapping("/queryDetailShow")
    public AjaxResult queryDetailShow(@RequestBody BizTransferRecords bizTransferRecords){
        return  iBizTransferRecordsService.queryDetailShow(bizTransferRecords);
    }
}
